<?php

class Morder extends CI_Model {
	
	public $table = 'tbl_order';
	public $pri_key="order_id";
	
	function __construct()

	{

		parent::__construct();

	}
	public function del_item($id)
	{
		$this->db->where($this->pri_key, $id);
		$this->db->delete($this->table); 
			
	}
	
	//****************** order    *************************//
	function sort_date($month,$year,$num,$off)
	{
		$sql = "select * from `order` where substring(`order_date`,4,2) ='".$month."' and substring(`order_date`,7,4)='".$year."' limit ".$num.",".$off;
		$query = $this->db->query($sql);
		//echo $sql;
	
		return $query->result_array();
		//print_r($query->result_array());
		
	}
	function num_sort_date($month,$year)
	{
		$sql = "select * from `order` where substring(`order_date`,4,2) ='".$month."' and substring(`order_date`,7,4)='".$year."'";
		$query = $this->db->query($sql);
		return $query->num_rows();
	}
	
	public function product_from_cate($id) 
	{
		$this->db->where($this->pri_key." =",$id);
		return $this->db->get($this->table)->result_array();
	}
	
	
	function list_data($num,$off)
	{
		$this->db->limit($off,$num);
		
		if($this->db->count_all($this->table) >0)
			{
				return $this->db->get($this->table)->result_array();
			}
		return false;
	}
		function insert_product($data)
	{
		if($this->db->insert($this->table,$data))
			return true;
		return false;
	
	}
	// update product category
	function update($data,$id)
	{
		if(is_numeric($id) && $id !='')
		{
			$this->db->where($this->pri_key,$id);
			if($this->db->update($this->table,$data))
				return true;
			return false;
			
		}
		return false;
	}
	
	public function info_from_id($id)
	{
			$this->db->where($this->pri_key.' =',$id);
		
		return $this->db->get($this->table)->result_array();
	}
	
	
		function delete()

	{

		if (isset($_POST['checkbox1']))

		{

			foreach($_POST['checkbox1'] as $id) {

				$row = $this->info_from_id($id,$this->table);

		
			//	print_r($row);
				//xoa file

		//		if ($row[0]['prod_img'] != 'null') unlink("./upload/product/".$row[0]['prod_img']);
			//	echo "<br /> ./upload/product/".$row[0]['prod_img'];
		

				//xoa CSDL

			//	$sql = "DELETE FROM human_resources WHERE id=$id";
				$this->db->where($this->pri_key, $id);
				$this->db->delete($this->table); 
				//$this->db->query($sql);

			}			

		}

	}
	
	
	// get info from id 
	
	
	

	
	// dem so record 
	function count_all()
	{
		return $this->db->count_all_results($this->table);
	}
	




 

}//end model class





/* End of file mhumans.php */

/* Location: ./system/application/models/mhumans.php */

?>